﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DSheet.Core;
using DSheet.Core.CommonData;

namespace DExcelServiceApp
{
    public partial class BYearList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                using (DBContext context = new DBContext())
                {
                    List<BYear> years = new CommonDataService().GetYears(context);

                    _ctlListYear.DataSource = years;
                    _ctlListYear.DataBind();
                }
            }
        }

        protected void _ctlBtnCreate_Click(object sender, EventArgs e)
        {
            using (DBContext context = new DBContext())
            {
                BYear newYear = new BYear();
                newYear.Id = Guid.NewGuid();
                newYear.Name = _ctlEditName.Text;
                new CommonDataService().SaveYear(context, newYear);

                List<BYear> years = new CommonDataService().GetYears(context);

                _ctlListYear.DataSource = years;
                _ctlListYear.DataBind();

                new CommonDataService().SyncYearsToDim(context);
            }
        }

        protected void _ctlBtnSync_Click(object sender, EventArgs e)
        {
            using (DBContext context = new DBContext())
            {
                new CommonDataService().SyncYearsToDim(context);
            }
        }
    }
}